package com.java.net;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.Socket;
public class Browser {
public static void main(String[] args) throws IOException {
    String host="www.baidu.com";
    int port=80;
    //创建服务访问对象（java中为socket对象）
    Socket socket=new Socket(host,port);
    //创建网络输入和输出流对象
    PrintWriter out=new PrintWriter(socket.getOutputStream(),true) ;//输出流
    InputStream in=socket.getInputStream();//输入流
    //基于输出流对象向服务端写数据表示发送请求
    out.println("GET /index.html HTTP/1.1");
    out.println();
    out.flush();
    //基于输入流对象读取服务端响应的结果
    byte[] buf=new byte[1024];
    int len=-1;
    while ((len=in.read(buf))!=-1){
       System.out.println(new String(buf,0,len));
    }
    in.close();
    out.close();
}
}
